package two.chapter_1.c1_2;

import edu.princeton.cs.algs4.StdDraw;

public class Interval1D {

    private double lo;
    private double hi;

    public Interval1D(double lo, double hi) {
        this.lo = lo;
        this.hi = hi;
    }

    public double getLo() {
        return lo;
    }

    public double getHi() {
        return hi;
    }

    public double length() {
        return Math.abs(hi - lo);
    }

    public boolean contains(double x) {
        if (x < lo || x > hi) {
            return false;
        }
        return true;
    }

    public boolean intersect(Interval1D that) {
        if (lo > that.hi) {
            return false;
        } else if (hi < that.lo) {
            return false;
        }
        return true;


    }

    public void draw() {
        StdDraw.line(lo, 0, hi, 0);
    }
}
